import {
    Entity,
    PrimaryGeneratedColumn,
    Column,
    CreateDateColumn,
    UpdateDateColumn,
    ManyToOne,
    JoinColumn
} from 'typeorm';
import { User } from '../../users/entities/user.entity';
import { Asset } from '../../assets/entities/asset.entity';

export type ApplicationStatus = 'pending' | 'approved' | 'rejected' | 'withdrawn';
export type ApplicationType = 'asset_tokenization' | 'investment' | 'withdrawal' | 'other';

@Entity('applications')
export class Application {
    @PrimaryGeneratedColumn()
    id: number;

    @ManyToOne(() => User, (user) => user.applications, { eager: true })
    @JoinColumn({ name: 'user_id' })
    user: User;

    @ManyToOne(() => Asset, { eager: true, nullable: true })
    @JoinColumn({ name: 'asset_id' })
    asset?: Asset;

    @Column({ type: 'enum', enum: ['asset_tokenization', 'investment', 'withdrawal', 'other'], default: 'other' })
    type: ApplicationType;

    @Column({ type: 'enum', enum: ['pending', 'approved', 'rejected', 'withdrawn'], default: 'pending' })
    status: ApplicationStatus;

    @Column()
    title: string;

    @Column({ type: 'text', nullable: true })
    description?: string;

    @Column({ type: 'json', nullable: true })
    data?: Record<string, any>;

    @Column({ type: 'text', nullable: true })
    remark?: string;

    @Column({ nullable: true })
    reviewedAt?: Date;

    @CreateDateColumn()
    createdAt: Date;

    @UpdateDateColumn()
    updatedAt: Date;
}
